package 学生管理系统;

import java.util.ArrayList;
import java.util.List;

public class ManagerSystem {
    private List<Student> studentList;

    public ManagerSystem() {
        this.studentList = new ArrayList<>();
    }

    //增加
    public void addStudent(Student student) {
        studentList.add(student);
        System.out.println("增加学生成功");
    }

    //删除
    public void deleteStudent(String ID) {
        for(Student student : studentList)
        {
            if(student.getID().equals(ID))
            {
                studentList.remove(student);
                System.out.println("已成功删除该学生");
                return;
            }
        }
        System.out.println("找不到该学生");
    }

    //查找
    public void searchStudent(String ID) {
        for (Student student : studentList) {
            if (student.getID().equals(ID)) {
                System.out.println("Student found:\n" + student.toString());
                return;
            }
        }
        System.out.println("Student not found.");
    }

    //更改
    public void updateStudent(String ID, String name, String gender, int age) {
        int falg = 0;
        for(Student student : studentList)
        {
            if(student.getID().equals(ID))
            {
                student.setName(name);
                student.setGender(gender);
                student.setAge(age);
                System.out.println("更改信息成功");
                falg = 1;
            }
        }
        if(falg == 0)
        System.out.println("未找到该学生");
    }

    //打印学生信息
    public void displayStudent() {
        if(studentList.isEmpty())
            System.out.println("该系统中没有学生信息");
        else {
            System.out.println("系统内学生信息如下");
            for (Student student : studentList)
            {
                System.out.println(student.toString());
                System.out.println("---------------------------------");
            }
        }
    }
}
